import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '@/layout'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

const originalReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace (location) {
  return originalReplace, call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'loginView',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dataoverview',
    meta: { title: 'sss' },
    children: [
      {
        path: 'dataoverview',
        name: 'DataOverview',
        component: () => import('@/views/dataoverview/index.vue')
      },
      {
        path: '/enterprise',
        name: 'EnterPrise',
        component: () => import('@/views/EnterPrise/index.vue')
      },
      {
        path: '/questionbank',
        name: 'QuestionBank',
        component: () => import('@/views/questionbank/index')
      },
      {
        path: '/subject',
        name: 'subject',
        component: () => import('@/views/subject/index')
      },
      {
        path: '/userlist',
        name: 'UserList',
        component: () => import('@/views/UserList')
      }
    ]
  },

  // { path: '*', redirect: '/404', hidden: true }
  {
    path: '*',
    name: '404NotFound',
    component: () => import('@/views/404.vue'),
    hidden: true
  }
]

const router = new VueRouter({
  routes
})

export default router
